

package com.jfinal.aceadmin.model;

import com.jfinal.ext.plugin.tablebind.TableBind;

import com.jfinal.plugin.activerecord.Db;

import java.util.ArrayList;
import java.util.List;

/**
 * <a href="UserNotification.java.html"><b><i>View Source</i></b></a>
 *
 * @author Jason
 *
 */
@TableBind(tableName = "UserNotification", pkName = "baseId")
public class UserNotification extends BaseModel<UserNotification> {
	private static final long serialVersionUID = 1L;
	public static UserNotification dao = new UserNotification();

	public long getBaseId() {
		return this.get("baseId");
	}

	public void setBaseId(long baseId) {
		this.set("baseId", baseId);
	}

	public int getUserId() {
		return this.get("userId");
	}

	public void setUserId(int userId) {
		this.set("userId", userId);
	}

	public String getDescription() {
		return this.get("description");
	}

	public void setDescription(String description) {
		this.set("description", description);
	}

	public int getType() {
		return this.get("type");
	}

	public void setType(int type) {
		this.set("type", type);
	}

	public boolean getReaded() {
		return this.get("readed");
	}

	public void setReaded(boolean readed) {
		this.set("readed", readed);
	}

	public int getQuantity() {
		return this.get("quantity");
	}

	public void setQuantity(int quantity) {
		this.set("quantity", quantity);
	}

	public List<UserNotification> findByUserId(int userId) {
		List<UserNotification> result = new ArrayList<UserNotification>();
		StringBuilder sBuilder = new StringBuilder(
				"SELECT * FROM UserNotification WHERE ");
		sBuilder.append("userId = ?");

		result = UserNotification.dao.find(sBuilder.toString(), userId);

		return result;
	}

	public int countByUserId(int userId) {
		int result = 0;
		StringBuilder sBuilder = new StringBuilder(
				"SELECT COUNT(*) FROM UserNotification WHERE ");
		sBuilder.append("userId = ?");
		result = Db.queryLong(sBuilder.toString(), userId).intValue();

		return result;
	}

	public List<UserNotification> findByUserIdAndRead(int userId, boolean readed) {
		List<UserNotification> result = new ArrayList<UserNotification>();
		StringBuilder sBuilder = new StringBuilder(
				"SELECT * FROM UserNotification WHERE ");
		sBuilder.append("userId = ?");
		sBuilder.append(" AND ");
		sBuilder.append("readed = ?");

		result = UserNotification.dao.find(sBuilder.toString(), userId, readed);

		return result;
	}

	public int countByUserIdAndRead(int userId, boolean readed) {
		int result = 0;
		StringBuilder sBuilder = new StringBuilder(
				"SELECT COUNT(*) FROM UserNotification WHERE ");
		sBuilder.append("userId = ?");
		sBuilder.append(" AND ");
		sBuilder.append("readed = ?");
		result = Db.queryLong(sBuilder.toString(), userId, readed).intValue();

		return result;
	}
}